package com.example.administrator.foodrowfresh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.models.HomepageBody;
import com.example.administrator.foodrowfresh.superBase.MyBaseAdapter;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/5/4.
 */
public class GridViewAdapterFive extends MyBaseAdapter {

    private List<HomepageBody.FloorItemBean> floorItemBeans;
    private LayoutInflater inflater;
    private String type;

    public GridViewAdapterFive(List list, Context mContext, String type) {
        super(list, mContext);
        this.floorItemBeans = list;
        this.inflater = LayoutInflater.from(mContext);
        this.type = type;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FiveViewHolder fiveViewHolder = null;
        if (convertView == null) {
            if ("3".equals(type) || "5".equals(type)) {
                convertView = inflater.inflate(R.layout.layout_gridview_five, parent, false);
            } else if ("4".equals(type)) {
                convertView = inflater.inflate(R.layout.layout_gridview_newproduct_item, parent, false);
            }else if ("2".equals(type))
            {
                convertView=inflater.inflate(R.layout.layout_gridview_more_item,parent,false);
            }
            fiveViewHolder = new FiveViewHolder(convertView);
            convertView.setTag(fiveViewHolder);
        } else {
            fiveViewHolder = (FiveViewHolder) convertView.getTag();
        }
        if ("3".equals(type) || "5".equals(type) || "4".equals(type)) {
            fiveViewHolder.textViewName.setText(floorItemBeans.get(position).getProductName());
            fiveViewHolder.textViewPrice.setText("￥" + floorItemBeans.get(position).getPRICE());
            fiveViewHolder.textViewWrigth.setText("/" + floorItemBeans.get(position).getWeight());
            x.image().bind(fiveViewHolder.imageView, floorItemBeans.get(position).getImage());
        }else if ("2".equals(type))
        {
            x.image().bind(fiveViewHolder.imageView,floorItemBeans.get(position).getUrl());
        }
        return convertView;
    }

    public class FiveViewHolder {
        TextView textViewName;
        TextView textViewPrice;
        TextView textViewWrigth;
        ImageView imageView;

        public FiveViewHolder(View convertView) {
            super();
            if ("3".equals(type) || "5".equals(type)) {
                textViewName = (TextView) convertView.findViewById(R.id.name_five);
                textViewPrice = (TextView) convertView.findViewById(R.id.price_five);
                textViewWrigth = (TextView) convertView.findViewById(R.id.weigth_five);
                imageView = (ImageView) convertView.findViewById(R.id.image_five);
            } else if ("4".equals(type)) {
                textViewName = (TextView) convertView.findViewById(R.id.name_five_new);
                textViewPrice = (TextView) convertView.findViewById(R.id.price_five_new);
                textViewWrigth = (TextView) convertView.findViewById(R.id.weigth_five_new);
                imageView = (ImageView) convertView.findViewById(R.id.image_five_new);
            }else if ("2".equals(type))
            {
                imageView= (ImageView) convertView.findViewById(R.id.more_item_icon);
            }
        }
    }

}
